package fybug.nulll.pdstream.WR.Err;
import com.sun.istack.internal.NotNull;
import com.sun.istack.internal.Nullable;

import java.io.Reader;
import java.io.Writer;

import static fybug.nulll.pdfunctionlibrary.Processing.Check.checkEquals;
import static fybug.nulll.pdfunctionlibrary.Processing.Check.equalsFidle;
/**
 * <h2>表示在字符流操作时发生错误.</h2>
 * <p>会记录发生错误的流和错误信息</p>
 * {@link #reader}<br/>
 * {@link #writer}
 *
 * @author fybug
 * @version 0.0.6
 * @since JDK 1.8
 */
public
class CharStreamErr extends Exception {
    private static final long serialVersionUID = -1206913601483649440L;
    /** <p>发生错误的读取流.</p> */
    @Nullable final public Reader reader;
    /** <p>发生错误的输出流.</p> */
    @Nullable final public Writer writer;

    public
    CharStreamErr(@NotNull final String s, @Nullable final Reader r, @Nullable final Writer w) {
        super(s);
        reader = r;
        writer = w;
    }

    @Override
    public
    boolean equals(@Nullable final Object obj) {
        switch ( checkEquals(this, obj) ) {
            default:
                return false;
            case 1:
                return true;
            case 2:
                return equalsFidle(reader, ((CharStreamErr) obj).reader) && equalsFidle(writer,
                                                                                        ((CharStreamErr) obj).writer);
        }
    }
}
